package com.ldc.commonlibs.uts

import android.app.Application
import android.content.pm.PackageInfo
import android.content.pm.PackageManager


/**
 *@description
 *@author liudc
 *@data 2022/6/17 22:19
 *
 */
class AppUtils {
    private var application: Application? = null

    companion object {
        val INSTANCE = SingleTon.S
    }

    private object SingleTon {
        val S = AppUtils()
    }

    fun initSDK(app: Application) {
        application = app
        DataStoreUts.INSTANCE.initSDK(app)
        ActivityUtils.init(app)
    }

    fun getApp(): Application = application!!


    private fun getPackageManager(): PackageManager {
        return getApp().packageManager
    }

    /**
     * 获取包信息
     */
    fun getPackageInfo(): PackageInfo {
        return getPackageManager().getPackageInfo(getApp().packageName, 0)
    }

    fun getAppName(): String {
        val labelRes = getPackageInfo().applicationInfo.labelRes
        return getApp().resources.getString(labelRes)
    }

    fun getAppVersionName(): String = getPackageInfo().versionName
    fun getAppVersionCode(): String = "${getPackageInfo().versionCode}"


}